package com.lmh.ymw.controller.order;

import com.lmh.ymw.entity.Product;
import com.lmh.ymw.entity.RespBean;
import com.lmh.ymw.service.product.ProductService;
import com.lmh.ymw.utils.ReturnResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
public class orderController {
    @Autowired
    ProductService productService;
    @GetMapping("/")
    public ReturnResult add(Integer entityId, Integer quantity){
        ReturnResult result = new ReturnResult();

        //查询出商品 ff
        Product product = productService.getProductById(entityId);
        if (product.getStock() < quantity) {
            return result.returnFail("商品数量不足");
        }
      /*  //获取购物车
        ShoppingCart cart = getCartFromSession(request);
        //往购物车放置商品
        result = cart.addItem(product, quantity);
        if (result.getStatus() == Constants.ReturnResult.SUCCESS) {
            cart.setSum((EmptyUtils.isEmpty(cart.getSum()) ? 0.0 : cart.getSum()) + (product.getPrice() * quantity * 1.0));
        }*/
        return result;
    }
}
